/**
 * 故障管理
 */
import * as React from "react";
import { message, Tabs } from "antd";
import moment from "moment";

import FaultManageCondition, {
  FaultManageConditionParam,
} from "./compontents/Condition";
import { getNetWorkData } from "../../../../utils/common";
import { faultTypeUrl } from "./compontents/serverApi";
import FaultManageTable, { FaultManageTableParam } from "./compontents/Table";
import "./index.less";

export interface FaultManageProps {}

export interface FaultManageState {}

const { TabPane } = Tabs;

class FaultManage extends React.Component<FaultManageProps, FaultManageState> {
  private faultTypeData: [] = [];
  private notTableParam: FaultManageTableParam = {
    isHandle: "0",
    faultType: 0,
    start: moment().subtract(7, "day").startOf("day").valueOf(),
    end: moment().endOf("day").valueOf(),
  };
  private yesTableParam: FaultManageTableParam = {
    isHandle: "1",
    faultType: 0,
    start: 0,
    end: 0,
  };

  render() {
    return (
      <div className="FaultManage">
        <Tabs defaultActiveKey="1">
          <TabPane tab="未处理" key="1">
            <FaultManageCondition
              faultTypeData={this.faultTypeData}
              query={(paramJson: FaultManageConditionParam) => {
                this.queryNot(paramJson);
              }}
            />
            <div className="subject">
              <FaultManageTable paramJson={this.notTableParam} />
            </div>
          </TabPane>
          <TabPane tab="已处理" key="2">
            <FaultManageCondition
              faultTypeData={this.faultTypeData}
              query={(paramJson: FaultManageConditionParam) => {
                this.queryYes(paramJson);
              }}
            />
            <div className="subject">
              <FaultManageTable paramJson={this.yesTableParam} />
            </div>
          </TabPane>
        </Tabs>
      </div>
    );
  }
  /**钩子函数 */
  componentWillMount() {
    this.init();
  }
  //初始化
  init() {
    getNetWorkData(faultTypeUrl, null, this, (result) => {
      if (result.success) {
        this.faultTypeData = result.data;
        this.forceUpdate();
      }
    });
  }
  //未处理
  queryNot(paramJson: FaultManageConditionParam) {
    if (paramJson.start === 0 || paramJson.end === 0) {
      message.info("请选择时间！");
      return;
    }
    this.notTableParam = {
      isHandle: "0",
      faultType: paramJson.faultType,
      start: paramJson.start,
      end: paramJson.end,
    };
    this.forceUpdate();
  }
  //已处理
  queryYes(paramJson: FaultManageConditionParam) {
    if (paramJson.start === 0 || paramJson.end === 0) {
      message.info("请选择时间！");
      return;
    }
    this.yesTableParam = {
      isHandle: "1",
      faultType: paramJson.faultType,
      start: paramJson.start,
      end: paramJson.end,
    };
    this.forceUpdate();
  }
}
export default FaultManage;
